package count.negative.gerti4.service;

import android.app.Activity;
import android.app.Application;
import android.os.AsyncTask;
import android.util.Log;

/**
 * 
 * @author count.negative
 * 
 * 
 */
public class RtvService extends ProgramService {
	final static String URL_ABEND = "http://m.rtv.de/?timeGroup=8&limitstart=0&stationType=1";
	final static String URL_JETZT = "http://m.rtv.de/?timeGroup=1&limitstart=0&stationType=1";

	public RtvService(Application app, Activity activity) {
		super(app, activity);
	}

	@Override
	public String getAbendHTML() {
		if (abend == null) {
			AsyncTask<String, Integer, String> task = new RtvService(app, activity).execute("abend", URL_ABEND);
			try {
				abend = task.get();
			} catch (Exception e) {
			}
		}

		return abend;
	}

	@Override
	public String getJetztHTML() {
		if (jetzt == null) {
			AsyncTask<String, Integer, String> task = new RtvService(app, activity).execute("jetzt", URL_JETZT);
			try {
				jetzt = task.get();
			} catch (Exception e) {
			}
		}

		return jetzt;
	}

	@Override
	protected String convertHTML(String html) {
		long start = System.currentTimeMillis();
		StringBuilder sb = new StringBuilder();

		html = removeTag(html, "<div id=\"siteHeader\"");
		html = removeTag(html, "<div id=\"siteTop\">", "\t\t</div>");
		html = removeTag(html, "<div id=\"siteFooter\"");
		html = removeTag(html, "<div id=\"amobeeAdDiv1\"");
		html = removeTag(html, "<div id=\"amobeeAdDiv2\"");
		html = removeTag(html, "<div class=\"labels\"");
		html = removeTag(html, "<a href=\"/showComments\" ");
		html = replaceAs(html);
		html = html.replace("<body>", "<body style=\"background-color:#ffffff;\">");
		html = html.replace("</head>", "</head><style>#siteMain{padding:0px;}</style>");
		html = html.replaceAll("onclick", "");
		sb.append(html);
		Log.i("PS", "convertHTML: " + (System.currentTimeMillis() - start));
		return sb.toString();
	}

}
